﻿using OdsServer.Common;
using OdsServer.DataTransfer;
using OdsServer.DataTransfer.Sockets;
using OdsServer.Tests;
using StructureMap;

namespace OdsServer.Core
{
    public static class IocHelper
    {
        public const string DebugProfile        = "Debug";
        public const string ProductionProfile   = "Release";

        public static void SetupIoc()
        {
            ObjectFactory.Configure(action =>
                {
                    action.Scan(sAction =>
                        {
                            sAction.AssemblyContainingType<OdsServerConfiguration>();
                            sAction.AssemblyContainingType<TransferService>();
                            sAction.AssemblyContainingType<OdsServerService>();
                            sAction.AssemblyContainingType<SocketTransfer>();
                            sAction.WithDefaultConventions();
                        } );

                    action.Profile( DebugProfile, pAction =>
                        {
                            pAction.For<IServerConfiguration>().Use<DebugConfiguration>();

                            pAction.For<OdsServerMarshalConfiguration>().Use<OdsServerMarshalConfiguration>();
                            pAction.For<OdsServerPipeConfiguration>().Use<OdsServerPipeConfiguration>();
                            pAction.For<OdsServerSocketConfiguration>().Use<OdsServerSocketConfiguration>();
                            pAction.For<SocketTransfer>().Use<SocketTransfer>();
                            pAction.For<IDeviceHandler>().Use<DebugDeviceHandler>();
                            pAction.For<ITransferService>().Use<TransferService>();
                            pAction.For<OdsServerService>().Use<OdsServerService>();
                        } );
                    action.Profile(ProductionProfile, pAction =>
                        {
                            pAction.For<IServerConfiguration>().UseSpecial(conf =>
                                {
                                    conf.IsThis(OdsServerConfiguration.GetInstance());
                                } );

                            pAction.For<OdsServerMarshalConfiguration>().Use<OdsServerMarshalConfiguration>();
                            pAction.For<OdsServerPipeConfiguration>().Use<OdsServerPipeConfiguration>();
                            pAction.For<OdsServerSocketConfiguration>().Use<OdsServerSocketConfiguration>();
                            pAction.For<SocketTransfer>().Use<SocketTransfer>();
                            pAction.For<ITransferService>().Use<TransferService>();
                            pAction.For<OdsServerService>().Use<OdsServerService>();
                        } );
                } );
        }

        public static void SetProfile(string profile)
        {
            ObjectFactory.Profile = profile;
        }
    }
}